package com.ttl.bc.ic.stktransfer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;



public class BCStkTransferAction extends DispatchAction {
	
	public ActionForward showFind(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
			throws Exception {
		request.setAttribute("dept", request.getParameter("dept"));
		
		new BCStkTransferBO().showFind(request);
		return mapping.findForward("success_stktransfer_showFind");
	}
	
	public ActionForward approve(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
			throws Exception {
				
//		BCStkIssueBO bo = new BCStkIssueBO();
//		BCStkIssue2Form issueform = bo.approveShow(request, response);
//		
//		String stkIssueDocNo = CommonUtils.getMaxStkIssueDocNo(issueform.getDocNo(), issueform.getDepartCode());//issueform.getDocNo();  
//		request.setAttribute("issue2form", issueform);
//		request.setAttribute("stkIssueDocNo", stkIssueDocNo);
		
		request.setAttribute("dept", request.getParameter("dept"));
		
		BCStkTransferBO bo = new BCStkTransferBO();						
		if (bo.approve(form, request, response)==true) {
			return mapping.findForward("success_approve_stktransfer");
		}else {
			//ทำ map กับการ fail_add
			return mapping.findForward("failure_approve_stktransfer");
		}
	}	

	public ActionForward add(ActionMapping mapping, ActionForm form, 
			HttpServletRequest request, HttpServletResponse response) throws Exception {		

		String dept = request.getParameter("dept");
		System.out.println("mode= add");
		BCStkTransferBO bo = new BCStkTransferBO();						
		if (bo.add(form, request, response)==true) {
			
			request.setAttribute("dept", dept);
			request.setAttribute("pageForward", "<meta http-equiv='refresh' content='1;url=stktransfer.do?mode=showFind&dept="+dept+"'>");
			return mapping.findForward("success_add_stktransfer");
		}else {
			//ทำ map กับการ fail_add
			return mapping.findForward("failure_add_stktransfer");
		}	
	}
	
	public ActionForward cancel(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
			throws Exception {				
		
		request.setAttribute("dept", request.getParameter("dept"));
		
		BCStkTransferBO bo = new BCStkTransferBO();						
		if (bo.cancel(form, request, response)==true) {
			return mapping.findForward("success_cancel_stktransfer");
		}else {
			//ทำ map กับการ fail_add
			return mapping.findForward("failure_cancel_stktransfer");
		}
	}
	
	public ActionForward delete(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
			throws Exception {				
		
		//request.setAttribute("dept", request.getParameter("dept"));
		
		BCStkTransferBO bo = new BCStkTransferBO();						
		if (bo.delete(form, request, response)==true) {
			return mapping.findForward("success_delete_stktransfer");
		}else {
			//ทำ map กับการ fail_add
			return mapping.findForward("failure_delete_stktransfer");
		}
	}	
}
